package com.un.ebs.data.conditions;

import lombok.AccessLevel;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

public class MergeSegments implements ISqlSegment {

    private final NormalSegmentList normal = new NormalSegmentList();
//    private final GroupBySegmentList groupBy = new GroupBySegmentList();
//    private final HavingSegmentList having = new HavingSegmentList();
//    private final OrderBySegmentList orderBy = new OrderBySegmentList();

    @Getter(AccessLevel.NONE)
    private final String sqlSegment = StringPool.EMPTY;
    @Getter(AccessLevel.NONE)
    private final boolean cacheSqlSegment = true;

    public void add(ISqlSegment... iSqlSegments) {
//        List<ISqlSegment> list = Arrays.asList(iSqlSegments);
//        ISqlSegment firstSqlSegment = list.get(0);
//        if (MatchSegment.ORDER_BY.match(firstSqlSegment)) {
//            orderBy.addAll(list);
//        } else if (MatchSegment.GROUP_BY.match(firstSqlSegment)) {
//            groupBy.addAll(list);
//        } else if (MatchSegment.HAVING.match(firstSqlSegment)) {
//            having.addAll(list);
//        } else {
//            normal.addAll(list);
//        }
//        cacheSqlSegment = false;
    }

    @Override
    public String getSqlSegment() {
//        if (cacheSqlSegment) {
//            return sqlSegment;
//        }
//        cacheSqlSegment = true;
//        if (normal.isEmpty()) {
//            if (!groupBy.isEmpty() || !orderBy.isEmpty()) {
//                sqlSegment = groupBy.getSqlSegment() + having.getSqlSegment() + orderBy.getSqlSegment();
//            }
//        } else {
//            sqlSegment = normal.getSqlSegment() + groupBy.getSqlSegment() + having.getSqlSegment() + orderBy.getSqlSegment();
//        }
//        return sqlSegment;
        return null;
    }
}